package com.zui.util.jms;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.zenith.yasoo.party.Person;
import com.zui.util.mail.MailManager;

/**
 * This is a message driven POJO, used to handle the email from the emailQueue
 * using apache-activemq4.1.1 for message broker.
 * 
 * @author zhaoyong
 */
public class MailMdp implements MessageListener {

	private MailManager mailManager;

	protected transient final Log log = LogFactory.getLog(getClass());

	public void onMessage(Message message) {
		// MapMessage mapMessage = (MapMessage) message;
		ObjectMessage objectMessage = (ObjectMessage) message;

		log.debug("MailMdp onMessage() method is invoked!");
		
		try {
			Person person = (Person) objectMessage.getObject();
			mailManager.sendSignupConfirmationMessage(person);
		} catch (JMSException e) {
			e.printStackTrace();
		}

	}

	public MailManager getMailManager() {
		return mailManager;
	}

	public void setMailManager(MailManager mailManager) {
		this.mailManager = mailManager;
	}

}
